package com.starry.push.netty.task;

import cn.hutool.core.collection.CollectionUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.starry.push.netty.domain.LogWsConnect;
import com.starry.push.netty.service.LogWsConnectService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @author WuChao
 * @version 1.0
 * @date 2020/11/9 16:46
 */
@Component
@Slf4j
public class Init implements InitializingBean {

    @Autowired
    private LogWsConnectService logWsConnectService;

    @Override
    public void afterPropertiesSet() throws Exception {
        log.info("服务启动中----》》》》 所有客户端强制下线");
        List<LogWsConnect> wsConnects = logWsConnectService.list(new QueryWrapper<LogWsConnect>()
                .eq(LogWsConnect.COL_STATUS, 0)
        );
        if (CollectionUtil.isNotEmpty(wsConnects)) {
            wsConnects.forEach(logWsConnect -> logWsConnect.setStatus(3));
            logWsConnectService.updateBatch(wsConnects);
        }


    }
}
